package com.bite.book.mode;

import com.bite.book.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
    private ResultCodeEnum code;//-1:失败；-2：出错；200：正确；
    private String errMag;
    private T data;
    //当登录成功时：
    public static <T>Result success(T data){
        Result result=new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setErrMag("");
        result.setData(data);
        return  result;
    }
    public static <T> Result fail(String errMag){
        Result result=new Result();
        result.setCode(ResultCodeEnum.FAIL);
        result.setErrMag(errMag);
        result.setData(null);
        return result;
    }
    public static <T> Result fail(String errMag,T data){
        Result result=new Result();
        result.setCode(ResultCodeEnum.FAIL);
        result.setErrMag(errMag);
        result.setData(data);
        return result;
    }
    public static <T> Result unlogin(){
        Result result=new Result();
        result.setCode(ResultCodeEnum.UNLOGIN);
        result.setErrMag("用户没有进行登录");
        return result;
    }
}
